package io.renren.modules.jxgk.service.impl;

import io.renren.modules.jxgk.dao.TeacherEvaluationSumDao;
import io.renren.modules.jxgk.entity.TeacherEvaluationSumEntity;
import io.renren.modules.jxgk.service.TeacherEvaluationSumService;
import io.renren.modules.jxgkphone.dao.TeachingEvaluationMapper;
import io.renren.modules.jxgkphone.entity.EvaluationContent;
import io.renren.modules.jxgkphone.entity.EvaluationLevel;
import io.renren.modules.jxgkphone.entity.EvaluationType;
import io.renren.modules.jxgkphone.tempEntity.TempEvaluation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TeacherEvaluationSumServiceImpl implements TeacherEvaluationSumService{
    @Autowired
    TeacherEvaluationSumDao teacherEvaluationSumDao;
    @Autowired
    TeachingEvaluationMapper teachingEvaluationMapper;
    @Override
    public List<TeacherEvaluationSumEntity> queryList(Map<String, Object> map){
        return teacherEvaluationSumDao.queryList(map);
    }
    @Override
    public int queryTotal(Map<String, Object> map){
        return  teacherEvaluationSumDao.queryTotal(map);
    }
    @Override
    public void deleteBatch(String[] termIds){
        teacherEvaluationSumDao.deleteBatch(termIds);
    }
    @Override
    public void save(TeacherEvaluationSumEntity ste){
        teacherEvaluationSumDao.save(ste);
    }
    @Override
    public TeacherEvaluationSumEntity queryObject(String index){
        return teacherEvaluationSumDao.queryObject(index);
    }
    @Override
    public void update(TeacherEvaluationSumEntity ste){
        teacherEvaluationSumDao.update(ste);
    }
    @Override
    public Object findAllEvaluationContentMap(Map<String, Object> map) {
        List<EvaluationContent> evaluationContentList=teacherEvaluationSumDao.findAllEvaluationContentList(map);
        List<EvaluationType> evaluationTypeList = teachingEvaluationMapper.findAllEvaluationType();
        List<EvaluationLevel> evaluationLevelList=teachingEvaluationMapper.findAllEvaluationLevel();
        for(EvaluationType evaluationType:evaluationTypeList)
        {
            List<EvaluationLevel> evaluationLevels=new ArrayList<>();
            for(EvaluationLevel evaluationLevel:evaluationLevelList)
            {
                if(evaluationLevel.getEvaluationTypeId().equals(evaluationType.getEvaluationTypeId()))
                {
                    List<EvaluationContent> evaluationContents=new ArrayList<>();
                    for(EvaluationContent evaluationContent:evaluationContentList)
                    {
                        if(evaluationContent.getEvaluationLevelId().equals(evaluationLevel.getEvaluationLevelId()))
                        {
                            evaluationContents.add(evaluationContent);
                            if(evaluationContent.isChecked())
                            {
                                evaluationLevel.setLevel(true);
                            }
                        }

                    }
                    evaluationLevel.setLevelContent(evaluationContents);
                    evaluationLevels.add(evaluationLevel);
                }
            }
            evaluationType.setContent(evaluationLevels);
        }
        return evaluationTypeList;
    }
}
